const path = require('path')
const ExtractTextPlugin = require("extract-text-webpack-plugin")
const  HtmlWebpackPlugin = require('html-webpack-plugin')
const webpack = require('webpack')
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')

module.exports = {
  entry: {
   main: "./src/main.js",
   stylus: "./src/scripts/stylus.js",
   less: "./src/scripts/less.js",
   sass: "./src/scripts/sass.js",
  },
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: path.join("js" ,"[name].js"),
    publicPath: "/dist/",
    library: "MyLibrary",
    libraryTarget: "umd",
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({
          fallback: "style-loader",
          use: "css-loader"
        })
      },
      {
        test: /\.scss$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: ['css-loader', 'sass-loader']
        })
      },
      {
        test: /\.less$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: ['css-loader', 'less-loader']
        })
      },
      {
        test: /\.styl$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: ['css-loader', 'stylus-loader']
        })
      },
      {
        test: /\.pug$/,
        loaders: ['html-loader', 'pug-html-loader']
      }
    ]
  },
  resolve: {
    modules: [
      "node_modules",
      path.resolve(__dirname, "src")
    ],
    extensions: [".js", ".json", ".jsx", ".css"],
    alias: {
      "@": path.resolve(__dirname, "src"),
    },
  },
  performance: {
    hints: "warning", // 枚举
    maxAssetSize: 200000, // 整数类型（以字节为单位）
    maxEntrypointSize: 400000, // 整数类型（以字节为单位）
    assetFilter: function(assetFilename) {
      // 提供资源文件名的断言函数
      return assetFilename.endsWith('.css') || assetFilename.endsWith('.js');
    }
  },

  devtool: "source-map",

  context: __dirname,

  target: "web", // 枚举

  externals: ["react", /^@angular\//, "vue"],

  stats: "errors-only",

  devServer: {
    proxy: { // proxy URLs to backend development server
      // '/api': 'http://localhost:3000'
    },
    contentBase: path.join(__dirname, 'dist'), // boolean | string | array, static file location
    compress: true, // enable gzip compression
    historyApiFallback: true, // true for index.html upon 404, object for multiple paths
    hot: true, // hot module replacement. Depends on HotModuleReplacementPlugin
    https: false, // true for self-signed, object for cert authority
    noInfo: true, // only errors & warns on hot reload
  },

  plugins: [
    new ExtractTextPlugin({filename: path.join("css", "[name].css")}),   
    new webpack.SourceMapDevToolPlugin({
      filename: path.join("js" ,"[name].js.map"),
      exclude: ['vendor.js']
    }),
    new UglifyJSPlugin(),
    new webpack.optimize.MinChunkSizePlugin({
      minChunkSize: 10000
    })
  ],

  node: {
  },

  recordsPath: path.resolve(__dirname, "build/records.json"),
  recordsInputPath: path.resolve(__dirname, "build/records.json"),
  recordsOutputPath: path.resolve(__dirname, "build/records.json"),
}